package com.mbyte.easy.listener;

import com.mbyte.easy.admin.entity.DraftLog;
import com.mbyte.easy.admin.service.IDraftLogService;
import com.mbyte.easy.admin.service.IDraftService;
import com.mbyte.easy.util.Utility;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @ClassName DraftLogEventListener
 * @Description 稿件日志事件监听
 * @Author lxt
 * @Date 2020/3/6 20:39
 */
@Slf4j
@Component
public class DraftLogEventListener {

    @Autowired
    private IDraftLogService draftLogService;

    @Autowired
    private IDraftService draftService;
    /**
     * @Description: 异步插入稿件日志
     * @param draftLog
     * @return: void 
     * @Author: lxt 
     * @Date: 2020/3/6 20:40
     */
//    @Async
    @EventListener
    public void syncSave(DraftLog draftLog) {
        log.info("开始执行插入稿件日志事件=>{}",draftLog);
        draftLog.setCreateTime(LocalDateTime.now());
        draftLog.setUserId(Utility.getSysUser().getId());
        draftLogService.save(draftLog);
        log.info("结束执行插入稿件日志事件");
    }

}
